<!-- 用户页面卡片组件-收藏的音乐 -->
<template>
  <div v-if="playlist.length">
    <div class="card-container">
      <div class="card-header">
        <div class="card-title">收藏的歌单</div>
      </div>
      <div class="card-list" v-for="(item, index) in playlist" :key="index">
        <div class="list-item-container" @click="$router.push(`/songlists?id=${item.id}`)" v-if="item.trackCount">
          <div class="cover-item-container">
            <div class="cover-item">
              <div>
                <img :src="item.coverImgUrl" alt="" />
              </div>
            </div>
          </div>
          <div class="list-item-content">
            <div class="first-line">{{ item.name }}</div>
            <div class="second-line">{{ num(item.trackCount) }}首，播放{{ num(item.playCount) }}次</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { userSongListAPI } from '@/api'
import { numberFormat } from '@/utils/common'

const route = useRoute()
let userId = route.query.id // 获取当前页面路由id值
let playlist = ref([]) // 用户歌单曲目

// 数字格式化
let num = computed(() => {
  return (val) => {
    return numberFormat(val)
  }
})

onMounted(() => {
  userSongList()
})

//获取用户歌单
function userSongList() {
  userSongListAPI({ uid: userId }).then((res) => {
    playlist.value = res.data.playlist.splice(1, 6)
  })
}
</script>

<style lang="scss" scoped>
.card-container {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  height: max-content;
  padding: 0 4.26666667vw;
  margin-top: 6.13333333vw;
  margin-bottom: 3.73333333vw;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  flex-direction: column;
  background-color: #fff;

  .card-header {
    -webkit-box-pack: justify;
    justify-content: space-between;
    -webkit-box-align: center;
    align-items: center;
    margin-bottom: 1.86666667vw;
    display: flex;

    .card-title {
      font-weight: 600;
      font-size: 4.26666667vw;
      line-height: 5.06666667vw;
      color: #333;
    }
  }

  .card-list>div:not(:last-of-type) {
    margin-bottom: 1.86666667vw;
  }

  .list-item-container {
    width: 100%;
    min-height: 14.13333333vw;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    -webkit-box-align: center;
    align-items: center;
    -webkit-box-pack: justify;
    justify-content: space-between;
    overflow: hidden;

    .cover-item-container {
      position: relative;
      z-index: 0;

      .cover-item,
      .cover-item>div {
        width: 13.33333333vw;
        height: 13.33333333vw;
        background-color: #b9b9b9;
        opacity: 1;
        border-radius: 2.13333333vw;
        position: relative;
      }

      .cover-item>div {
        overflow: hidden;
      }

      .cover-item>div>img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      .cover-item:before {
        position: absolute;
        content: ' ';
        border-radius: 2.13333333vw;
        background: #000;
        opacity: 0.05;
        width: 11.2vw;
        height: 11.2vw;
        top: -0.8vw;
        left: 50%;
        transform: translateX(-50%);
        z-index: -10;
      }
    }

    .list-item-content {
      -webkit-box-flex: 1;
      flex: 1;
      margin-left: 2.66666667vw;
      overflow: hidden;

      >div {
        max-width: 66.93333333vw;
        width: 100%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      .first-line {
        font-weight: 400;
        font-size: 4.26666667vw;
        line-height: 5.06666667vw;
        color: #333;
      }

      .second-line {
        font-style: normal;
        font-weight: 400;
        font-size: 3.2vw;
        line-height: 3.73333333vw;
        color: #999;
        margin-top: 0.8vw;
      }
    }
  }
}
</style>